﻿using System.Collections.Generic;
using System.Collections.ObjectModel;

using octalforty.Syndication.Core;

namespace octalforty.Syndication.Core.Rss
{
    /// <summary>
    /// Represents a collection of <see cref="RssItem"/> objects.
    /// </summary>
    /// <remarks>
    /// Implementation of the <see cref="IList{T}"/> interface is required
    /// for this collection to be wrapped by <see cref="SyndicationFeedItemCollection"/>.
    /// </remarks>
    public sealed class RssItemCollection : Collection<RssItem>, IList<ISyndicationFeedItem>
    {
        /// <summary>
        /// Initializes a new instance of <see cref="RssItemCollection"/> class.
        /// </summary>
        public RssItemCollection()
        {
        }

        #region IList<ISyndicationFeedItem> Members
        int IList<ISyndicationFeedItem>.IndexOf(ISyndicationFeedItem item)
        {
            return IndexOf((RssItem)item);
        }

        void IList<ISyndicationFeedItem>.Insert(int index, ISyndicationFeedItem item)
        {
            Insert(index, (RssItem)item);
        }

        ISyndicationFeedItem IList<ISyndicationFeedItem>.this[int index]
        {
            get { return (this as Collection<RssItem>)[index]; }
            set { this[index] = (RssItem)value; }
        }

        void ICollection<ISyndicationFeedItem>.Add(ISyndicationFeedItem item)
        {
            Add((RssItem)item);
        }

        bool ICollection<ISyndicationFeedItem>.Contains(ISyndicationFeedItem item)
        {
            return Contains((RssItem)item);
        }

        void ICollection<ISyndicationFeedItem>.CopyTo(ISyndicationFeedItem[] array, int arrayIndex)
        {
            CopyTo((RssItem[])array, arrayIndex);
        }

        bool ICollection<ISyndicationFeedItem>.Remove(ISyndicationFeedItem item)
        {
            return Remove((RssItem)item);
        }

        bool ICollection<ISyndicationFeedItem>.IsReadOnly
        {
            get { return false; }
        }

        IEnumerator<ISyndicationFeedItem> IEnumerable<ISyndicationFeedItem>.GetEnumerator()
        {
            return (IEnumerator<ISyndicationFeedItem>)GetEnumerator();
        }
        #endregion
    }
}
